package org.example.managere.repository.feibiao;

import org.example.managere.entity.feibiao.AmAapMotorKn;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

/**
 * 电机知识表数据访问接口
 */
public interface AmAapMotorKnRepository extends JpaRepository<AmAapMotorKn, Integer> {
    
    /**
     * 全文搜索混合文本（使用idx_hybrid_search索引）
     */
    @Query(value = "SELECT * FROM am_aap_motorkn WHERE MATCH(hybridData) AGAINST(:keyword IN BOOLEAN MODE)",
           countQuery = "SELECT COUNT(*) FROM am_aap_motorkn WHERE MATCH(hybridData) AGAINST(:keyword IN BOOLEAN MODE)",
           nativeQuery = true)
    Page<AmAapMotorKn> searchByHybridData(@Param("keyword") String keyword, Pageable pageable);
    
    /**
     * 全文搜索分析结果（使用idx_analysis_search索引）
     */
    @Query(value = "SELECT * FROM am_aap_motorkn WHERE MATCH(llmAnalysis) AGAINST(:keyword IN BOOLEAN MODE)",
           countQuery = "SELECT COUNT(*) FROM am_aap_motorkn WHERE MATCH(llmAnalysis) AGAINST(:keyword IN BOOLEAN MODE)",
           nativeQuery = true)
    Page<AmAapMotorKn> searchByLlmAnalysis(@Param("keyword") String keyword, Pageable pageable);
    
    /**
     * 备选的混合文本搜索方法（使用LIKE）
     */
    @Query(value = "SELECT * FROM am_aap_motorkn WHERE hybridData LIKE CONCAT('%', :keyword, '%')",
           countQuery = "SELECT COUNT(*) FROM am_aap_motorkn WHERE hybridData LIKE CONCAT('%', :keyword, '%')",
           nativeQuery = true)
    Page<AmAapMotorKn> searchByHybridDataWithLike(@Param("keyword") String keyword, Pageable pageable);
    
    /**
     * 备选的分析结果搜索方法（使用LIKE）
     */
    @Query(value = "SELECT * FROM am_aap_motorkn WHERE llmAnalysis LIKE CONCAT('%', :keyword, '%')",
           countQuery = "SELECT COUNT(*) FROM am_aap_motorkn WHERE llmAnalysis LIKE CONCAT('%', :keyword, '%')",
           nativeQuery = true)
    Page<AmAapMotorKn> searchByLlmAnalysisWithLike(@Param("keyword") String keyword, Pageable pageable);
} 